package com.jhgsys.internal.sypq.controller;

import com.jhgsys.internal.common.annotation.Log;
import com.jhgsys.internal.common.controller.BaseController;
import com.jhgsys.internal.common.entity.FebsConstant;
import com.jhgsys.internal.common.entity.FebsResponse;
import com.jhgsys.internal.common.exception.FebsException;
import com.jhgsys.internal.sypq.entity.*;
import com.jhgsys.internal.sypq.service.ITaskTestbl1Service;
import com.jhgsys.internal.sypq.service.ITaskTestbl2Service;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 试验内容 Controller
 *
 * @author ganjun
 * @date 2024-11-18 11:13:09
 */
@Slf4j
@Validated
@Controller
public class TaskTestbl2Controller extends BaseController {

    @Autowired
    private ITaskTestbl2Service taskTestbl2Service;



    @GetMapping(FebsConstant.VIEW_PREFIX + "taskTestbl2/row")
       public String taskTestEdit(Model model, TaskTestbl2 test){
        if(0==test.getId()){
            test.setId(null);
        }
        if("undefined".equals(test.getOarsCode())){
            test.setOarsCode(null);
        }
        if("undefined".equals(test.getDiameter())){
            test.setDiameter(null);
        }
        if("undefined".equals(test.getSurface())){
            test.setSurface(null);
        }
        if("undefined".equals(test.getDirect())){
            test.setDirect(null);
        }

        if("undefined".equals(test.getRemark())){
            test.setRemark(null);
        }
        model.addAttribute("taskTestbl2",test);
        return jumpPage("sypq/taskTestbl2/taskTestbl2Edit");
    }



    @Log("修改TaskTest")
    @PostMapping("taskTestbl2/update")
    @ResponseBody
    @RequiresPermissions("taskTest:edit")
    public FebsResponse updateTaskTest(TaskTestbl2 test) throws FebsException {
        try {
            if(test.getId()==null||test.getId()<1){
                taskTestbl2Service.createTaskTestbl2(test);
            }else {
                taskTestbl2Service.updateTaskTestbl2(test);
            }
            return success();
        } catch (Exception ex) {
            return failure(ex,"修改失败");
        }
    }




}
